﻿/// 此JS应放在submit.js之后

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Ext.namespace('EHSubmit.Goal.ListByTeacher');
//作业信息列表

//列模式
EHSubmit.Goal.ListByTeacher.ColumnModel = new Ext.grid.ColumnModel([
    { header: '作业ID', sortable: true, hidden: true, dataIndex: 'ID' },
    { header: '作业名', width: 400, sortable: true, hidden: false, dataIndex: 'Title' },
	{ header: '类型', width: 80, sortable: true, hidden: false, renderer: EHSubmit.Format.goalTypeRenderer, dataIndex: 'GoalType' },
    { header: '布置时间', width: 200, sortable: true, renderer: Ext.util.Format.dateRenderer('Y年m月d日'), dataIndex: 'PublishTime' },
    { header: '最后期限', width: 200, sortable: true, renderer: Ext.util.Format.dateRenderer('Y年m月d日'), dataIndex: 'DeadLine' },
    { header: '附件', width: 60, sortable: false, renderer: EHSubmit.Format.goalAttachRenderer, dataIndex: 'AttachPath' },
    { header: '说明', sortable: false, dataIndex: 'Description' }
]);

//数据源
EHSubmit.Goal.ListByTeacher.Store = new Ext.data.Store({
    baseParams: { Op: 'listTchGoal' },      // 需要传递操作参数  sid学生的ID
    proxy: new Ext.data.HttpProxy({ url: EHSubmit.ajaxRoot + 'GoalHandler.ashx' }),  //后台具体处理

    reader: new Ext.data.JsonReader({
            totalProperty: 'count',    //总记录个数
            root: 'data',
            id: 'ID'
        },
        [   // 数据模型
            {name: 'ID' },
            { name: 'Title' },
			{ name: 'GoalType' },
            { name: 'PublishTime' },
            { name: 'DeadLine' },
            { name: 'AttachPath' },
            { name: 'Description' },
			{ name: 'GoalType' }
    ]),
    listeners: {
        /// 加载异常处理
        exception: function(proxy, type, action, options, response){
            Ext.MessageBox.alert('数据加载错误!','请与管理员联系');
            
        }
    }
});


//////////////////////////////////////////////////////////////////////
//// 填写作业信息,文件等
EHSubmit.Goal.ListByTeacher.ModifyForm = {
    xtype: 'form',
    id: 'ListGoalGrid_ModifyForm',
    //autoHeight:true,
    height: 330,
    //disabled: true,      // 未选择任何作业时不能提交
    //title: '修改主观题作业',
    fileUpload: true,    // 上传Form
    labelAlign: 'left',
    buttonAlign: 'center',
    bodyStyle: 'padding:15px;',
    frame: true,
    border: false,
    labelWidth: 80,
    monitorValid: true,

    defaults: { anchor: '95%', allowBlank: false, msgTarget: 'side' },
    items: [
        { // 作业信息
            xtype: 'textfield',
            name: 'goalTitle',
            blankText: '请在左边列表中选择一个班级',
            fieldLabel: '作业信息'
        },
        { // 隐藏域,保存GID
            xtype: 'hidden',
            name: 'courseId'
        },
        { // 上交期限
            xtype: 'datefield',
            name: 'deadline',
            format: 'Y年n月j日',
            blankText: '请选择最迟上交时间',
            fieldLabel: '最迟上交期限'
        },
        
        { // 文件上传
            xtype: 'fileuploadfield',
            emptyText: '选择一个文件',
            fieldLabel: '文件',
            name: 'filePath',
            allowBlank: true,
            buttonText: ' 浏览... '
            //            buttonCfg: {
            //                iconCls: 'upload-icon'
            //            }

        },
        { // 作业说明字段
            xtype: 'htmleditor',
            fieldLabel: '作业说明',
            emptyText: '这里填写作业说明',
            name: 'description',
            blankText: '请填写此次作业的说明',
            height: 150,
            enableAlignments: false,
            enableLists: false
            //value: 'test'
        }
    ],
    buttons: [{
        text: '提交修改',
        handler: function() {
            EHSubmit.closeWin(EHSubmit.Goal.ListByTeacher.ModifyWin);
        }
    }, {
        text: '取消',
        handler: function() {
            EHSubmit.closeWin(EHSubmit.Goal.ListByTeacher.ModifyWin);
        }
    }]

  
};

EHSubmit.Goal.ListByTeacher.ModifyWin ={
	id: 'ModifyWin',
	xtype: 'window',
	//plain: true,
	border: true,
	autoHeight:true,
	layout: 'fit',
	modal: true,
	title: '提交作业(主观题)',
	frame: true,
	layout:'form',
	items:[EHSubmit.Goal.ListByTeacher.ModifyForm]	
}



// 数据列表
EHSubmit.Goal.ListByTeacher.GridPanel = {
    xtype: 'grid',
    id: 'ListGoalGrid_teacher',
    layout: 'fit',
    //autoHeight:true,
    height: 500,
    border: true,
    frame: true,
    loadMask: true,          // 加载数据时遮住
    cm: EHSubmit.Goal.ListByTeacher.ColumnModel,
    ds: EHSubmit.Goal.ListByTeacher.Store,
    sm: new Ext.grid.RowSelectionModel({
        singleSelect: true,              // 一次只选一个
        listeners: {
            /// 选中一个作业,在右边显示相关信息
            rowselect: function(sm, row, rec) {
                ///// 选中一项作业后，将选中的记录存在 EHSubmit.Goal.ListByTeacher.selectedRecord中
                //EHSubmit.Goal.ListByTeacher.selectedRecord = rec;

            }
        }
    }),
    // 工具条
    tbar: [{
        text: '刷新',
        iconCls: 'refresh',
        handler: function() {
            EHSubmit.Goal.ListByTeacher.Store.load();
        }
    },{
        text: '修改',
        tooltip: '修改选定的作业信息',
        iconCls: 'modify',
        handler: function() {
           // 没有选择作业
            if (!EHSubmit.Goal.ListByTeacher.selectedRecord) {
                Ext.MessageBox.alert('提示', '请选择一项作业');
            } 
            else {
                var type = EHSubmit.Goal.ListByTeacher.selectedRecord.get('GoalType');
                if (type == 0) {
                    EHSubmit.showWin(EHSubmit.Goal.ListByTeacher.ModifyWin);
                    return;
                }

                //mainPanel.getEl().mask();
                EHSubmit.showWin(EHSubmit.Goal.Modify.WinConfig);
                var form = Ext.getCmp('ListGoalGrid_ModifyForm');
                //赋值
//                form.getForm().findField('t').setValue(EHSubmit.Goal.ListByTeacher.selectedRecord.get('ID'));
//                form.getForm().findField('goalId').setValue(EHSubmit.Goal.ListByTeacher.selectedRecord.get('GoalID'));
//                form.getForm().findField('goalTitle').setValue(EHSubmit.Goal.ListByTeacher.selectedRecord.get('GoalName'));
//                form.getForm().findField('description').setValue(EHSubmit.Goal.ListByTeacher.selectedRecord.get('Description'));

            }
        }
        // Place a reference in the GridPanel  可能相当于一个标记
        //ref: '../topRemoveButton',
        //disabled: true
      }],
        bbar: {
            xtype: 'paging',
            pageSize: 10,                 //只是起计算页数的作用，不影响表面,内部影响start 和 limit
            store: EHSubmit.Goal.ListByTeacher.Store,
            displayInfo: true,
            displayMsg: '显示第 {0} 条到 {1} 条记录，一共 {2} 条',
            emptyMsg: '没有记录'

        },
        listeners: {
            render: function(thisGrid) {
                //----------请求单页数据-----------------
                thisGrid.store.load({ params: { start: 0, limit: 10} });
            },
            rowclick:function (thisGrid,rowIndex,e ){
			// ***主观题***
			    //////显示当前选择的作业
			    /*EHSubmit.showWin(EHSubmit.Work.Submit.SubmitWin);
    			
			    var form = Ext.getCmp('soSubmitForm');			
			    var store = thisGrid.getStore();
                var rec = store.getAt(rowIndex);
			    form.getForm().findField('goalId').setValue(rec.get('ID'));
			    form.getForm().findField('goalTitle').setValue(rec.get('Title'));
			    */
			    var store = thisGrid.getStore();
                var rec = store.getAt(rowIndex);
    			
			    EHSubmit.Goal.ListByTeacher.selectedRecord = rec;
            },
            //        render: function(g) {
            //            g.getSelectionModel().selectRow(0);
            //        },
            delay: 10 // Allow rows to be rendered.
        }

    };



    //////////////////////////////////////////////////////////////////////
    /// 内部容器窗口包含选择和上传
    EHSubmit.Goal.ListByTeacher.innerForm = {
        layout: 'fit',
        border: false,
        /*title: '提交作业',
        height: 400,
        frame: true,
        */
        defaults: { bodyStyle: 'padding:5px;', border: false },
        items: [EHSubmit.Goal.ListByTeacher.GridPanel]
    }


////////////////////////////////////////////////////////////////
EHSubmit.Goal.ListByTeacher.Tab = {
    id:'goalList_teacher',
    layout: 'form',
    frame: false,
    closable: true,
    title: '查看已布置作业',
    bodyStyle: 'padding:5px;',
    border: false,
    items: [EHSubmit.Goal.ListByTeacher.innerForm]
};

